package com.sh.data.engine.domain.normalization.modeldesign.model.model.enums;

import com.sh.data.engine.domain.normalization.modeldesign.model.model.domain.StorageDomain;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 字段枚举
 *
 * @author : changkong
 * @date : 2022/3/6
 */
public enum HiveFieldTypeEnum {
    TINYINT("tinyint"),
    SMALLINT("smallint"),
    INT("int"),
    BIGINT("bigint"),

    FLOAT("float"),
    DOUBLE("double"),
    DECIMAL("decimal(20,10)"),

    TIMESTAMP("timestamp"),

    CHAR("char(255)"),
    STRING("string"),
    VARCHAR("varchar(400)"),
    DATE("date"),
    BOOLEAN("boolean"),
    BINARY("binary");

    private final String dbFieldType;

    HiveFieldTypeEnum(String dbFieldType) {
        this.dbFieldType = dbFieldType;
    }

    public String getDbFieldType() {
        return dbFieldType;
    }

    public static List<StorageDomain.FieldType> getAllFieldType() {
        HiveFieldTypeEnum[] values = HiveFieldTypeEnum.values();
        return Arrays.stream(values)
            .map(i -> new StorageDomain.FieldType(i.dbFieldType, i.name()))
            .collect(Collectors.toList());
    }

    public static List<String> getMdAllFieldType() {
        HiveFieldTypeEnum[] values = HiveFieldTypeEnum.values();
        return Arrays.stream(values).map(i -> i.dbFieldType).collect(Collectors.toList());
    }
}
